﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VDS.RDF;
using VDS.RDF.Query;

namespace GeoNames2RDF
{
   internal static class TriplesHelper
   {
      public static string GetGeoNamesTripleString(string geoNameId, string predicateName, string literalObject)
      {
         SparqlParameterizedString sparqlParameterizedString = new SparqlParameterizedString("@s @p @o . ");
         sparqlParameterizedString.SetUri("@s", new Uri(NamesHelper.GetGeoNamesEntityUri(geoNameId)));
         sparqlParameterizedString.SetUri("@p", new Uri(NamesHelper.GetGeoNamesOntologyUri(predicateName)));
         sparqlParameterizedString.SetLiteral("@o", literalObject);

         return sparqlParameterizedString.ToString();
      }

      public static string GetGeoNamesTripleString(string geoNameId, string predicateName, string literalObject, string language)
      {
         SparqlParameterizedString sparqlParameterizedString = new SparqlParameterizedString("@s @p @o . ");
         sparqlParameterizedString.SetUri("@s", new Uri(NamesHelper.GetGeoNamesEntityUri(geoNameId)));
         sparqlParameterizedString.SetUri("@p", new Uri(NamesHelper.GetGeoNamesOntologyUri(predicateName)));
         sparqlParameterizedString.SetLiteral("@o", literalObject, language);

         return sparqlParameterizedString.ToString();
      }

      public static string GetGeoNamesTripleString(string geoNameId, string predicateName, int value)
      {
         SparqlParameterizedString sparqlParameterizedString = new SparqlParameterizedString("@s @p @o . ");
         sparqlParameterizedString.SetUri("@s", new Uri(NamesHelper.GetGeoNamesEntityUri(geoNameId)));
         sparqlParameterizedString.SetUri("@p", new Uri(NamesHelper.GetGeoNamesOntologyUri(predicateName)));
         sparqlParameterizedString.SetLiteral("@o", value);

         return sparqlParameterizedString.ToString();
      }

      public static string GetGeoNamesTripleString(string geoNameId, string predicateName, Uri uri)
      {
         SparqlParameterizedString sparqlParameterizedString = new SparqlParameterizedString("@s @p @o . ");
         sparqlParameterizedString.SetUri("@s", new Uri(NamesHelper.GetGeoNamesEntityUri(geoNameId)));
         sparqlParameterizedString.SetUri("@p", new Uri(NamesHelper.GetGeoNamesOntologyUri(predicateName)));
         sparqlParameterizedString.SetUri("@o", uri);

         return sparqlParameterizedString.ToString();
      }

      public static string GetWgs84TripleString(string geoNameId, string predicateName, string literalObject)
      {
         SparqlParameterizedString sparqlParameterizedString = new SparqlParameterizedString("@s @p @o . ");
         sparqlParameterizedString.SetUri("@s", new Uri(NamesHelper.GetGeoNamesEntityUri(geoNameId)));
         sparqlParameterizedString.SetUri("@p", new Uri(NamesHelper.GetWgs84Uri(predicateName)));
         sparqlParameterizedString.SetLiteral("@o", literalObject);

         return sparqlParameterizedString.ToString();
      }

      public static string GetWgs84TripleString(string geoNameId, string predicateName, decimal literalObject)
      {
         SparqlParameterizedString sparqlParameterizedString = new SparqlParameterizedString("@s @p @o . ");
         sparqlParameterizedString.SetUri("@s", new Uri(NamesHelper.GetGeoNamesEntityUri(geoNameId)));
         sparqlParameterizedString.SetUri("@p", new Uri(NamesHelper.GetWgs84Uri(predicateName)));
         sparqlParameterizedString.SetLiteral("@o", literalObject);

         return sparqlParameterizedString.ToString();
      }
   }
}
